
<?php
$row = NULL;
$num = 0;
/*$status = "opening";
$Process = "";*/
$result = '';



if(isset($_SESSION['applicant_id']))
{
	$app_id = $_SESSION['app_id'];
	$contact_id=$_SESSION['CurrentContact_id'];
	
	isConfirm($app_id);
	
	$loanResult = getLoanStatus($app_id);	
	 
	$contractStatus = getContractstatus($app_id);
	
	$status = $loanResult['status'];	
	
	$Process = strtolower($loanResult['MC_Process']);
                   
	$loanStatus = checkLoanNodays($app_id);
	
	//print_r($app_id);
	//exit; 
	 
	$CreatedContract = $contractStatus['contractprepared'];
	$VerifyEsign = $contractStatus['contractsigned'];
    //var_export($loanResult);
	/*hot coded Status*/
	
	if($loanStatus['no_days'] > 30)
	{
		$loanStatusUpdate = "UPDATE crm_application SET status = 'close' WHERE app_id = ".$app_id;
		//mysql_query($loanStatusUpdate);
		$_SESSION['loan_exp'] = 'older than 30 days';
		header('Location:index.php?dashboard'); exit;
		//echo 'older than 30 days';
	}
	$app_id = $_SESSION['app_id'];
	$row = getVerificationStatus($app_id);
}
//echo 'AppID : '.$app_id .' Contact ID :' .$contact_id;
?>


<?php 
if($status != 'close' && $Process != 'confirm')
{
	
	include('verify-process.php');
	/* 
	if($row != NULL && $row['idcheck_status'] == 0 && $row['payslip_status'] == 0 && $row['bankretrieve_status'] == 0)
	{
		include('verify-process.php');
	}
	else if($row != NULL && $row['idcheck_status'] == 0 && $row['payslip_status'] == 1 && $row['bankretrieve_status'] == 1)
	{
		header('Location:index.php?verify-photo-id');
	}
	else if($row != NULL && $row['idcheck_status'] == 0 && $row['payslip_status'] == 0 && $row['bankretrieve_status'] == 1)
	{
		header('Location:index.php?verify-photo-id');
	}
	else if($row != NULL && $row['idcheck_status'] == 1 && $row['payslip_status'] == 0 && $row['bankretrieve_status'] == 0)
	{
		header('Location:index.php?verify-employment');
	}
	else if($row != NULL && $row['idcheck_status'] == 1 && $row['payslip_status'] == 1 && $row['bankretrieve_status'] == 0)
	{
		header('Location:index.php?verify-bank');
	} 
	else if($row != NULL && $row['idcheck_status'] == 1 && $row['payslip_status'] == 0 && $row['bankretrieve_status'] == 1)
	{
		header('Location:index.php?verify-employment');
	}	
	else if($row != NULL && $row['idcheck_status'] == 0 && $row['payslip_status'] == 1 && $row['bankretrieve_status'] == 0)
	{
		header('Location:index.php?verify-photo-id');
	}	
	
	else if($row != NULL && $row['idcheck_status'] == 1 && $row['payslip_status'] == 1 && $row['bankretrieve_status'] == 1)
	{
		include('verify-process.php');
	}
	
*/}
/*elseif($status != 'close' && $Process == 'confirm' && $CreatedContract == 0 && $VerifyEsign == 0)
{
	if($row != NULL && $row['idcheck_status'] == 1 && $row['payslip_status'] == 1 && $row['bankretrieve_status'] == 1)
	{
		include('verify-process.php');
	}
}*/
elseif($status != 'close' && $Process == 'confirm')
{
	
	if($CreatedContract == 1 && $VerifyEsign == 0){
	include('sign-contract.php');
	}elseif($CreatedContract == 1 && $VerifyEsign == 1){
		include('getmoney.php');
	}
	else
	{
		include('verify-process.php');
	}
}

else
{
	include('reloan.php');
}
?>
        <div class="modal fade" id="successmodel" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display:none">
          <div class="modal-dialog">
            <div class="modal-content">
            <div class="modal-header" style="height:30px;"><strong style="font-size:18px; color:#FFF;">Pre-Approved*</strong> <p align="right" style="margin-top:-20px;">
            
            <a id="warningClose" data-dismiss="modal" href="#"><strong>close</strong> </a>
            </p></div>
              <div class="modal-body" style="max-height: 450px">
                <!--<div id="successtext" style="font-size:14px; font-family:Arial, Helvetica, sans-serif"></div>
                <script type="text/javascript"  src="assets/js/success.js"></script> -->
                <p>Congratulations, your loan has been <span style="color:#0C3; font-weight:bold;">Pre-Approved*</span> for <?php if(isset($_SESSION['ela'])) echo $_SESSION['ela']; ?> For verification purposes, required documents must be provided.To get money ASAP, please login to your account manager and upload them now.</p>
                <p style="color:#999; font-size:10px;">*All applications are subject to income, asset, credit history and other details verification as well as lending criteria and lender's approval.</p>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
              </div>
            </div>
          </div> 
        </div>
      <script>
	  <?php if(isset($_SESSION['ela']) && $_SESSION['ela'] == 600): ?>
	   $(window).load(function(){
        $('#successmodel').modal('show');
    });
	   <?php endif; ?>
	  </script>